import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import { AppContainer } from 'react-hot-loader';

/**
 * redux demo 1
 */
// import { ADD, DEL, JQ } from './model/demo1';
// import { createStore } from 'redux';
// const store =  createStore(JQ);
// //console.log(store.getState());
// store.dispatch({type: ADD, payload:2});
// //console.log(store.getState());
// store.subscribe(()=>{
//     console.log(store.getState());
// })
// setTimeout(()=>{
//     store.dispatch({type: DEL, payload:20});
// }, 4000)

/**
 * redux demo 2
 * App.js demo2 展示
 */
import { createStore } from 'redux';
import { JQ } from './model/demo1';
const store = createStore(JQ);


const render = (Component, store) => {
    ReactDOM.render(
        <AppContainer>
            <Component store={store} />
        </AppContainer>
    , document.getElementById('root'))
}
render(App, store);
registerServiceWorker();

if(module.hot){
    module.hot.accept('./App', () => { // 监控根节点如果更新了就触发render
        render(App, store)
    })
}

/**
 * redux demo 2
 */
store.subscribe(()=>{
    render(App, store);
})